<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
        <h1 onclick="dji()">点击我</h1>
</body>
    <script>
            function dji(){
                ws = new WebSocket("ws://192.168.2.7:2348");
                ws.onopen = function() {
                    ws.send('tom');
                    alert("给服务端发送一个字符串：tom");
                };
                ws.onmessage = function(e) {
                    alert("收到服务端的消息：" + e.data);
                };
            }

    </script>
</html>